package com.hzit.auth.handler;

import com.hzit.common.util.R;
import com.hzit.common.util.ResponseUtil;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 类名：
 * 作者：WF
 * 功能：处理认证失败的逻辑
 */
@Component
public class HzitAuthenticationEntryPoint implements AuthenticationEntryPoint {
	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
		R<Object> r = R.fail(HttpStatus.UNAUTHORIZED,"认证失败！");
		ResponseUtil.out(response,r);
	}
}
